package aspectj;

import org.junit.Test;
import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;

/**
 * @Author 肖地洋
 * @Date 2022/5/4 16:57
 */
public class test {
    @Test
    public void test01(){
        String config = "aop.xml";
        ApplicationContext ctx = new ClassPathXmlApplicationContext(config);
        //从容器中获取对象
        SomeService proxy = (SomeService) ctx.getBean("someService");
        System.out.println(proxy.getClass().getName());//com.sun.proxy.$Proxy6  jdk动态代理对象
        proxy.doSome("李四",24);
    }

    @Test
    public void test02(){
        String config = "aop.xml";
        ApplicationContext ctx = new ClassPathXmlApplicationContext(config);
        //从容器中获取对象
        SomeService proxy = (SomeService) ctx.getBean("someService");
        String str =  proxy.doSome("李四",24);
        System.out.println(str);
    }

    @Test
    public void test03(){
        /**
         * cglib动态代理
         */
        String config = "aop.xml";
        ApplicationContext ctx = new ClassPathXmlApplicationContext(config);
        //从容器中获取对象
        SomeServideCglib proxy = (SomeServideCglib) ctx.getBean("someServiceCglib");
        String str =  proxy.doSome("李四",24);
        System.out.println(proxy.getClass().getName());//aspectj.SomeServideCglib$$EnhancerBySpringCGLIB$$d1acf0f9

        System.out.println(str);
    }

}
